package dp;

public class Candy135 {
    public int candy(int[] ratings) {
        int[] dpLeft = new int[ratings.length];
        int[] dpRight = new int[ratings.length];

        for (int i = 0; i < ratings.length; i++) {
            dpLeft[i]=1;
            dpRight[i]=1;
        }
        for (int i = 1; i < ratings.length; i++) {
            if(ratings[i]-ratings[i-1]>0){
                dpLeft[i] = dpLeft[i-1]+1;
            }
            if(ratings[ratings.length-1-i]-ratings[ratings.length-1-(i-1)]>0){
                dpRight[ratings.length-1-i]=dpRight[ratings.length-1-(i-1)]+1;
            }
        }
        int sum = 0;
        for (int i = 0; i < dpLeft.length; i++) {
            sum = sum+Math.max(dpLeft[i],dpRight[i]);
        }
        return sum;
    }
}
